{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">
                后台菜单
            </li>
            <li class="">
                <a href="{:url('admin/menu/add')}">
                    添加菜单
                </a>
            </li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <table id="table">
                </table>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
layui.use('table',function(){
    var h = document.body.scrollHeight;;
    console.log(h);
    var table=layui.table;
    table.render({
    elem: '#table'
    ,height: h-220
    ,url: '/admin/menu/index' //数据接口
    ,page: true //开启分页
    ,size: 'sm'
    ,limit: 20
    ,cols: [[ //表头
          {field: 'id', title: 'ID', width:50, sort: true, fixed: 'left'}
          ,{field: 'sort', title: '排序', width:60}
          ,{field: 'title', title: '菜单名称', width:150, templet:function(d){
            if(d.level>0){
                var str='|';
                for(var i=0;i<d.level;i++)
                    str+='--';
                return str+d.title;
            }else{
                return d.title;
            }
          }}
          ,{field: 'name', title: '控制器方法', width:220} 
          ,{field: 'status', title: '状态', width: 60,templet:function(d){
            return d.status==1 ? '显示' : '隐藏';
          }}
          ,{field: 'type', title: '操作', width: 250, templet:'#action'}
    ]]
  });
})
</script>
<script type="text/html" id="action">
    <a class="layui-btn layui-btn-xs" href="admin/menu/add/pid/{{d.id}}">
        添加子菜单
    </a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" href="admin/menu/edit/id/{{d.id}}">
        编辑
    </a>
    <a class="layui-btn layui-btn-danger layui-btn-xs ajax-delete" href="admin/menu/delete/id/{{d.id}}">
        删除
    </a>
</script>
{/block}
